package com.tanhua.server.controller;

import com.tanhua.server.service.VideoService;
import com.tanhua.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

@RestController
@RequestMapping("/smallVideos")
public class VideoController {


    @Autowired
    private VideoService videoService;

    @PostMapping(name = "上传小视频")
    public ResponseEntity saveSmallVideos(MultipartFile videoThumbnail,MultipartFile videoFile) throws Exception{

        return videoService.saveSmallVideos(videoThumbnail,videoFile);
    }

    @GetMapping(name = "分页查询小视频列表")
    public ResponseEntity querySmallVideos(@RequestParam(defaultValue = "1") Integer page,
                                           @RequestParam(defaultValue = "10")Integer pagesize) throws Exception{
        PageResult pageResult = videoService.querySmallVideos(page, pagesize);
        return ResponseEntity.ok(pageResult);
    }
    @PostMapping(value = "/{uid}/userFocus",name = "关注视频博主")
    public ResponseEntity userFocus(@PathVariable("uid") Long focusUserId) throws Exception{
        return videoService.userFocus(focusUserId);

    }
    @PostMapping(value = "/{uid}/userUnFocus",name = "取消关注视频博主")
    public ResponseEntity userUnFocus(@PathVariable("uid") Long focusUserId) throws Exception{
        return videoService.userUnFocus(focusUserId);
    }

    //  /smallVideos/:id/dislike
    //对小视频点赞
    @PostMapping(value = "/{id}/dislike",name = "对小视频点赞")
    public ResponseEntity videoLike(@PathVariable("id") String videoId){
        return videoService.videoLike(videoId);
    }

    //对小视频取消点赞
    // /smallVideos/:id/like
    @PostMapping(value = "/{id}/like",name = "对小视频取消点赞")
    public ResponseEntity videoDislike(@PathVariable("id") String videoId){
        return videoService.videoDislike(videoId);
    }

    //  /smallVideos/:id/comments
    @GetMapping(value = "/{id}/comments",name = "分页查询小视频评论")
    public  ResponseEntity queryComments(@RequestParam(defaultValue = "1") Integer page,
                                         @RequestParam(defaultValue = "10")Integer pagesize,
                                         @PathVariable("id") String videoId){
        return videoService.queryComments(videoId,page,pagesize);
    }

    //  /smallVideos/:id/comments
    //发评论
    @PostMapping(value = "/{id}/comments",name = "小视频发评论")
    public ResponseEntity comments(@PathVariable("id") String videoId, @RequestBody Map map){
        String comment = (String) map.get("comment");
        return videoService.saveComments(videoId,comment);
    }


}
